from django.db import models

# Create your models here.
from apiTest.models import TestCaseGroup
from common.common_models import CommonInfo


class TaskInfo(CommonInfo):
    class Meta:
        verbose_name = "任务调度详情表"
        db_table = "task_info"

    project_id = models.BigIntegerField("项目id", null=False)
    group_id_list = models.ManyToManyField(TestCaseGroup)
    name = models.CharField("任务名称", null=False, max_length=30)
    env_id = models.IntegerField("环境id", default=0)
    cron_expression = models.CharField("表达式", null=True, max_length=30)
    remark = models.CharField("备注", null=True, blank=True, max_length=255)
    status = models.BooleanField(default=True)
    is_send_email = models.BooleanField(default=False)
    is_send_ding_ding = models.BooleanField(default=False)
    email_list = models.CharField("收件人邮件列表", null=True, max_length=255)


class TaskLog(CommonInfo):
    class Meta:
        verbose_name = "任务日志表"
        db_table = "task_log"

    status = (
        (0, "进行中"),
        (1, "执行成功"),
        (2, "执行失败"),
        (3, "执行异常"),
    )
    project_id = models.BigIntegerField("项目id", null=False)
    task_id = models.BigIntegerField("任务id", null=False)
    task_name = models.CharField("任务名字", null=True, blank=True, max_length=100)
    status = models.IntegerField("任务状态", choices=status, null=False)
    group_total = models.IntegerField("用例集总数", null=False)
    group_pass_total = models.IntegerField("成功用例集总数", null=False)
    group_failed_total = models.IntegerField("失败用例集总数", null=False)
    case_total = models.IntegerField("测试用例总数", null=False)
    case_failed_total = models.IntegerField("失败测试用例总数", null=False)
    cass_pass_total = models.IntegerField("成功测试用例总数", null=False)
    cass_skip_total = models.IntegerField("测试用例跳过条数", null=False)
    time_consuming = models.IntegerField("任务执行时长", null=False)
    exception_log = models.CharField("错误日志", null=True, max_length=255)
